using System;
using System.ComponentModel;
using System.Resources;
using System.Windows.Forms;
using Infragistics.Win.UltraWinTabControl;
using Infragistics.Win.UltraWinTabs;

namespace PluginFrame
{
	public class AbstractPcrExperimentViewService : IPcrExperimentViewService, IPcrFormControl, IPlugin, IProvideService
	{
		protected ResourceManager mResourceManager;

		protected IApplication mApplication;

		protected string mName = "";

		protected string mDescription = "";

		protected int mIndex;

		protected IPcrSystemService mPcrSystemService;

		protected IPcrDataService mPcrDataService;

		protected IConfigurationService mConfigurationService;

		protected IMiscService mMiscService;

		protected IPcrLogService mPcrLogService;

		protected IPcrStructure mPcrStructure;

		protected ControlPosition mControlPosition;

		protected ControlLocation mControlLocation;

		protected UltraTabControl mTabControl;

		protected string mTabControlName;

		protected IPcrExperiment mPcrExperiment;

		protected bool mIsChanged;

		public bool IsChanged
		{
			get
			{
				return mIsChanged;
			}
			set
			{
				mIsChanged = value;
			}
		}

		public IApplication Application
		{
			get
			{
				return mApplication;
			}
			set
			{
				mApplication = value;
			}
		}

		public int Index
		{
			get
			{
				return mIndex;
			}
			set
			{
				mIndex = value;
			}
		}

		public string Name
		{
			get
			{
				return mName;
			}
			set
			{
				mName = value;
			}
		}

		public string Description
		{
			get
			{
				return mDescription;
			}
			set
			{
				mDescription = value;
			}
		}

		public ControlPosition GetControlPosition
		{
			get
			{
				return mControlPosition;
			}
		}

		public ControlLocation GetControlLocation
		{
			get
			{
				return mControlLocation;
			}
		}

		public event EventHandler<EventArgs> PluginEvent;

		public void Execute(object[] context)
		{
		}

		public object ProvideService()
		{
			return null;
		}

		public void UnLoad()
		{
			mApplication.RemoveService(mName);
		}

		public virtual void Load()
		{
			if (mApplication != null)
			{
				mApplication.AddService(mName, this);
				mControlPosition = ControlPosition.TopChartView;
				mControlLocation = ControlLocation.RunView;
				mTabControl = new UltraTabControl();
				mConfigurationService = (IConfigurationService)mApplication.GetService("ConfigurationService");
				mPcrDataService = (IPcrDataService)mApplication.GetService("PcrDataService");
				mPcrLogService = (IPcrLogService)mApplication.GetService("PcrLogService");
				mPcrSystemService = (IPcrSystemService)mApplication.GetService("PcrSystemService");
			}
		}

		public void AddTabPage(UltraTab tabPage)
		{
			if (tabPage != null)
			{
				((ISupportInitialize)mTabControl).BeginInit();
				mTabControl.SuspendLayout();
				mTabControl.Controls.Add(tabPage.TabPage);
				mTabControl.Tabs.Add(tabPage);
				((ISupportInitialize)mTabControl).EndInit();
				mTabControl.ResumeLayout(false);
			}
		}

		public UltraTab GetTabPage(int pageIndex)
		{
			if (pageIndex >= 0 && pageIndex < mTabControl.Tabs.Count)
			{
				return mTabControl.Tabs[pageIndex];
			}
			return null;
		}

		public void SetTabActive(int pageIndex)
		{
			if (pageIndex >= 0 && pageIndex < mTabControl.Tabs.Count)
			{
				mTabControl.SelectedTab = mTabControl.Tabs[pageIndex];
				mTabControl.ActiveTab = mTabControl.Tabs[pageIndex];
			}
		}

		public void SetVisible(bool isVisible)
		{
			mTabControl.Visible = isVisible;
		}

		public bool UpdatePcrStructure()
		{
			return true;
		}

		public virtual void CreateControls(AddControl addControl, IPcrExperiment pcrExperiment)
		{
			mPcrExperiment = pcrExperiment;
			((ISupportInitialize)mTabControl).BeginInit();
			mTabControl.Dock = DockStyle.Fill;
			mTabControl.Name = mTabControlName;
			mTabControl.ViewStyle = ViewStyle.VisualStudio2005;
			mTabControl.Style = UltraTabControlStyle.Excel;
			mTabControl.TabLayoutStyle = TabLayoutStyle.SingleRowJustified;
			mTabControl.TabOrientation = TabOrientation.Default;
			mTabControl.ScrollButtons = TabScrollButtons.None;
			mTabControl.AllowTabClosing = false;
			mTabControl.AllowTabMoving = false;
			mTabControl.Tag = pcrExperiment;
			((ISupportInitialize)mTabControl).EndInit();
			addControl(mControlPosition, mControlLocation, mTabControl, pcrExperiment);
		}
	}
}
